home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8511 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  956 b 

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem Negating an Unsigned Char
  5. Date: 4 Mar 1996 11:28:28 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4hfg8sINNhbq@keats.ugrad.cs.ubc.ca>
  8. References: <Dnnros.Lq.0.-s@hkusuc.hku.hk> <4he27sINNdel@keats.ugrad.cs.ubc.ca> <4he5f0$acv@solutions.solon.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4he5f0$acv@solutions.solon.com>,
  12. Peter Seebach <seebs@solutions.solon.com> wrote:
  13. >Close, but the cigar yet escapes you.
  14. >
  15. >    if (a == (~b & ((1 << CHAR_BIT) - 1)))
  16.  
  17. By the way, if you wanted to do this without the cast to unsigned char, why not
  18. use UCHAR_MAX? We know that this is a Mercenne number, 2^n-1, so you can just
  19. AND with that. Can UCHAR_MAX ever be something other than a dyadic power less
  20. one?
  21.  
  22.     if (a == (~b & UCHAR_MAX))
  23.  
  24. That way you avoid the shifts.
  25.  
  26. -- 
  27.  
  28.